# coding=utf-8

import pygame
from scene import SceneManager
from scene import Scene1, Scene2
from scene_test import SceneTest
from scene_test_result import SceneTestResult
from scene_test_choose import SceneTestChoose
from scene_console_test_choose import SceneConsoleTestChoose
from config_manager import ConfigManager

WIN_WIDTH = 1600
WIN_HEIGHT = 800


# 主程序
def main():
    test_init = SceneConsoleTestChoose()
    config = ConfigManager()
    params = test_init.menu(config)
    print(params)
    # exit(0)
    # params = {}
    # params["question_group"] = test_grp
    # params["question_count"] = 7

    pygame.init()
    screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
    pygame.display.set_caption("Scene Switching Example")

    scenes = {
        "test": SceneTest(),
        "test_result": SceneTestResult(),
        "test_choose": SceneTestChoose(),
        "test_console_choose": SceneConsoleTestChoose(),
        "scene1": Scene1(),
        "scene2": Scene2(),
    }

    # scene_manager = SceneManager(scenes, "test_console_choose")
    scene_manager = SceneManager(scenes, "test", params)
    # scene_manager = SceneManager(scenes, "test_choose")
    # scene_manager

    running = True
    clock = pygame.time.Clock()
    while running:
        time_delta = clock.tick(60)
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                running = False

        is_gui = scene_manager.process_events(events)
        if is_gui:
            if not screen:
                screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
                pygame.display.set_caption("Scene Switching Example")
        else:
            if screen:
                pygame.display.quit()
                screen = None

        scene_manager.update(time_delta)

        if screen:
            screen.fill((255, 255, 255))
            scene_manager.draw(screen)

            pygame.display.flip()

    pygame.quit()

if __name__ == "__main__":
    main()
